<template>
  <div class="app-container">
    <el-container style="height: 900px; border: 1px solid #eee; ">
      <el-main>
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="项目名称" prop="itemName">
            <el-select v-model="queryParams.itemId" placeholder="请选择项目" @change="itemChange" clearable size="small">
              <el-option
                v-for="dict in itemList"
                :key="dict.id+''"
                :label="dict.name"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="楼号" prop="floorId">
            <el-select v-model="queryParams.floorId" placeholder="请选择楼号" clearable size="small">
              <el-option
                v-for="dict in floorList"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="feeinfoList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="类目名称" align="center" prop="categoryName" />
          <el-table-column label="费用类型" align="center" prop="feeType">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.fee_type" :value="scope.row.feeType"/>
            </template>
          </el-table-column>
          <el-table-column label="人工总价" align="center" prop="laborTotal">
            <template slot-scope="scope">
              <span style="color: red" v-if="scope.row.remark.indexOf('0')>=0">{{scope.row.laborTotal}}</span>
              <span  v-if="scope.row.remark.indexOf('0')<0">{{scope.row.laborTotal}}</span>
            </template>
          </el-table-column>
          <el-table-column label="材料总价" align="center" prop="materialTotal">
            <template slot-scope="scope">
              <span style="color: red" v-if="scope.row.remark.indexOf('1')>=0">{{scope.row.materialTotal}}</span>
              <span  v-if="scope.row.remark.indexOf('1')<0">{{scope.row.materialTotal}}</span>
            </template>
          </el-table-column>
          <el-table-column label="机械总价" align="center" prop="machineryTotal">
            <template slot-scope="scope">
              <span style="color: red" v-if="scope.row.remark.indexOf('2')>=0">{{scope.row.machineryTotal}}</span>
              <span  v-if="scope.row.remark.indexOf('2')<0">{{scope.row.machineryTotal}}</span>
            </template>
          </el-table-column>
        </el-table>
<!--        <pagination-->
<!--          v-show="total>0"-->
<!--          :total="total"-->
<!--          :page-size="clientPage.pageSize"-->
<!--          :current-page="clientPage.pageNum"-->
<!--          @pagination="paging"-->
<!--        />-->
      </el-main>
    </el-container>
  </div>
</template>

<script>
import {selectWarnReport,getFloorList,getItemList} from "@/api/feesys/feeinfo";
import ZhaiTree from '@/components/ZhaiTree'
import { getToken } from "@/utils/auth";
export default {
  name: "Feeinfo",
  dicts: ['fee_type', 'unit_type'],
  components: {
    ZhaiTree
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 费用管理表格数据
      feeinfoList: [],
      feeAllList:[],
      itemList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      floorList:[],
      item:{},
      btnStatus:true,
      uploadFileDrawer:false,
      category:null,
      clientPage:{
        // 默认显示第几页
        pageNum: 1, // 当前页码
        pageSize: 10, // 每页的数据条数
      },
      // 上传参数
      upload: {
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/feesys/fileinfo/upload/",
        // 上传的文件列表
        fileList: []
      },
      categoryRemark:"测试备注",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemId: null,
        itemName: null,
        categoryId: null,
        categoryName: null,
        ancestors: null,
        floorId: null,
        floorName: null,
        feeType: "1",
        detailBody: null,
        featureDes: null,
        unitId: null
      },
      // 表单参数
      form: {}
    };
  },
  created() {
    this.getItemList();
  },
  methods: {
    /** 查询费用管理列表 */
    getList() {
      this.loading = true;
      selectWarnReport(this.queryParams).then(response => {
        this.feeinfoList = response.data;
        this.total=this.feeAllList.length;
        // this.paging();
        this.loading = false;
      });
    },
    getItemList(){
      getItemList().then(response => {
        this.itemList=response.data;
        if(this.itemList){
          this.initQuery(this.itemList[0].id);
        }
      })
    },
    initQuery(itemId){
      this.resetQuery();
      //获取列表
      this.queryParams.itemId=itemId;
      // this.getList();
      //获取楼号
      let obj={};
      obj.itemId=itemId;
      obj.status=0;
      this.getFloorList(obj);
    },
    getFloorList(obj){
      getFloorList(obj).then(response => {
        this.floorList=response.data;
      })
    },
    itemChange(itemId){
      if(itemId){
        this.initQuery(itemId);
      }
    },
    setFlag(scope,categoryId,feeType){
      // let arry=this.itemList.filter(f=>f.categoryId==categoryId);
      // let obj=arry.filter(f=>f.feeType==feeType);
      // let obj1=arry.filter(f=>f.feeType!=feeType);
      // if(feeType==1){
      //   if(obj.)
      // }
      console.log(scope)
      return 1;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 分页方法
    paging() {
      this.feeinfoList = this.feeAllList.slice((this.clientPage.pageNum - 1) * this.clientPage.pageSize, (this.clientPage.pageNum - 1) * this.clientPage.pageSize + this.clientPage.pageSize)
    },
    handleCurrentChange(val) {
      console.log("aaaa"+val)
      this.clientPage.pageNum = val
      this.paging()
    },
    handleSizeChange(val) {
      console.log("bbb"+val)
      this.clientPage.pageSize = val
      this.paging()
    },
  }
};
</script>
